package viqiang.ye.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import viqiang.ye.HelloService;

@RestController
public class HelloController {

    /**
     * 通过Dubbo的@Reference注解注入需要使用的interface，类似于Spring的@Autowired
     * 通过loadbalance指定负载均衡机制
     */
    @Reference(loadbalance = RoundRobinLoadBalance.NAME, timeout = 2000)
    private HelloService helloService;

    @GetMapping("/hello/{message}")
    public String hello(@PathVariable String message) {
        return this.helloService.hello(message);
    }
}
